package com.sq.partner.manager.controller.credit;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sq.partner.manager.common.Constants;
import com.sq.partner.manager.common.DictCache;
import com.sq.partner.manager.common.Result;
import com.sq.partner.manager.mybatis.model.CoinFeeConfig;
import com.sq.partner.manager.mybatis.model.CoinPlanConfig;
import com.sq.partner.manager.mybatis.model.CoreDept;
import com.sq.partner.manager.mybatis.model.CreditPlan;
import com.sq.partner.manager.mybatis.model.CreditProduct;
import com.sq.partner.manager.mybatis.model.DictDto;
import com.sq.partner.manager.mybatis.model.GatewayChannelInfo;
import com.sq.partner.manager.mybatis.model.GatewaySubChannel;
import com.sq.partner.manager.mybatis.model.GatewayUser;
import com.sq.partner.manager.mybatis.model.CreditPlan;
import com.sq.partner.manager.mybatis.model.NlifePlan;
import com.sq.partner.manager.mybatis.model.SaleConfig;
import com.sq.partner.manager.mybatis.model.TradAgentInfo;
import com.sq.partner.manager.mybatis.model.TradAgentInfoRela;
import com.sq.partner.manager.mybatis.model.TradInsuPlanGroup;
import com.sq.partner.manager.mybatis.model.TradPlanSale;
import com.sq.partner.manager.mybatis.model.credit.credit10008;
import com.sq.partner.manager.service.CoinFeeConfigService;
import com.sq.partner.manager.service.CoinPlanConfigService;
import com.sq.partner.manager.service.IGatewaySubChannelService;
import com.sq.partner.manager.service.INlifePlanConfigService;
import com.sq.partner.manager.service.ITradInsuPlanGroupService;
import com.sq.partner.manager.service.SaleConfigService;
import com.sq.partner.manager.service.TradPlanSaleService;
import com.sq.partner.manager.service.TradSmsTemplateService;
import com.sq.partner.manager.service.credit.CreditPlanService;
import com.sq.partner.manager.service.credit.CreditProductService;
import com.sq.partner.manager.util.FreeMarkerUtil;
import com.sq.partner.manager.util.JsonUtils;
import com.sq.partner.manager.util.LogUtil;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.SqlUtil;
import com.sq.partner.manager.util.StrUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

@Controller
@RequestMapping(value = "/CreditPlan")
public class CreditPlanController {
	private static Logger logger = LogUtil.getLog(CreditPlanController.class);
	@Resource
	private CreditPlanService creditPlanService;
	@Resource
	private CreditProductService creditProductService;

	@Resource
	private TradSmsTemplateService tradSmsTemplateService;

	@Resource
	TradPlanSaleService tradPlanSaleService;
	@Resource
	private SaleConfigService saleConfigService;
	@Resource
	ITradInsuPlanGroupService insuPlanGroupService; 
	@Resource
	private IGatewaySubChannelService subChannelService;
	@Resource
	private CoinFeeConfigService coinFeeConfigService;
	@Resource
	private CoinPlanConfigService coinPlanConfigService;
	
	@Resource
	private INlifePlanConfigService nlifePlanConfigService;

	@RequestMapping(value = "/list")
	public String list() throws Exception {
		logger.debug("forward CreditPlan   successful....");
		return "credit/plan/list";
	}

	/**
	 * 分页条件查询合作伙伴
	 * 
	 * @param session
	 * @param page
	 * @param channelInfo
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryChannelInfoPageByCriteria")
	@ResponseBody
	public Page<GatewayChannelInfo> queryChannelInfoPageByCriteria(
			HttpSession session, Page<GatewayChannelInfo> page,
			GatewayChannelInfo channelInfo) throws Exception {
		GatewayUser gatewayuser = (GatewayUser) session
				.getAttribute(Constants.SESSION_USER);
		page.setDepts(gatewayuser.getDepts());
		page.setType(channelInfo);

		page = creditPlanService.queryChannelInfoPageByCriteria(page);

		return page;
	}

	/**
	 * 分页条件查询方案
	 * 
	 * @param session
	 * @param page
	 * @param creditPlan
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryPlanList")
	@ResponseBody
	public Page<Map<String, Object>> queryPlanList(HttpSession session,
			Page<Map<String, Object>> page, CreditPlan creditPlan)
			throws Exception {

		GatewayUser user = (GatewayUser) session
				.getAttribute(Constants.SESSION_USER);
		String privilegedDeptStr = user.getDepartmentStr();
		String userCodes = com.sq.partner.manager.common.Config
				.getProp("imple.nlife.userCodes");
		/** 方案导出，查询是否有导出权限 */
		String[] codes = forPlans(userCodes);
		boolean flag = false;
		logger.info("登录用户名：" + user.getUserCode() + "   配置的用户名： " + userCodes);
		if (codes != null && codes.length > 0) {
			flag = Arrays.asList(codes).contains(user.getUserCode());
		}
		Map<String, Object> paramMap = SqlUtil.buildPageMap(page);
		paramMap.put("privilegedDeptStr", privilegedDeptStr == null ? "''"
				: privilegedDeptStr.substring(1, 3));
		paramMap.put("partner_code", creditPlan.getPartner_code() == null ? ""
				: creditPlan.getPartner_code());
		paramMap.put("plan_code", creditPlan.getPlan_code() == null ? ""
				: creditPlan.getPlan_code());
		paramMap.put("plan_name", creditPlan.getPlan_name() == null ? ""
				: creditPlan.getPlan_name());
		paramMap.put("prod_code", creditPlan.getProd_code() == null ? ""
				: creditPlan.getProd_code());
		page.setMap(paramMap);
		page.setObj(flag);
		page = creditPlanService.queryPlanListByCriteria(page);
		return page;
	}

	/** 产品号处理 */
	private String[] forPlans(String plan_code) {
		if (StrUtil.isEmpty(plan_code)) {
			return null;
		}
		String[] strs = plan_code.split(",");
		return strs;
	}

	/**
	 * 跳转至新增方案页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/toAddCreditPlan")
	public String toAddCreditPlan(ModelMap model) throws Exception {

		creditPlanService.toAddCreditPlan(model);

		return "credit/plan/addOrEdit";
	}

	/**
	 * 客户查询
	 * 
	 * @param identifyNo
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryCust")
	@ResponseBody
	public credit10008 queryCust(credit10008 credit10008, String href)
			throws Exception {
		credit10008 cust = creditPlanService.queryCustBy(credit10008, href);
		return cust;
	}

	/**
	 * 更新方案关联的个人代理信息
	 * 
	 * @param session
	 * @param plan_code
	 * @param isPrintCard
	 * @param agentInfoListStr
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateAgentInfoRela")
	@ResponseBody
	public Result updateAgentInfoRela(HttpSession session, String plan_code,
			String isPrintCard, String agentInfoListStr, String agent_type)
			throws Exception {
		GatewayUser user = (GatewayUser) session
				.getAttribute(Constants.SESSION_USER);

		if (StrUtil.isEmpty(plan_code)) {
			return Result.error("方案号不能为空");
		}
		if (StrUtil.isEmpty(agentInfoListStr)) {
			return Result.error("代理信息不能为空");
		}
		List<String> list = new ArrayList<String>();

		// 创建一个JsonParser
		JsonParser jsonParser = new JsonParser();
		// 通过JsonParser对象可以把json格式的字符串解析成一个JsonElement对象
		JsonElement jsonElement = jsonParser.parse(agentInfoListStr);
		// 把JsonElement对象转换成JsonArray
		JsonArray jsonArray = null;
		if (jsonElement.isJsonArray()) {
			jsonArray = jsonElement.getAsJsonArray();
		} else {
			return Result.error("无效的代理信息");
		}
		for (JsonElement je : jsonArray) {
			if (je.getAsJsonObject().get("id") == null) {
				continue;
			}
			String id = je.getAsJsonObject().get("id").getAsString();
			if ("Y".equals(isPrintCard)) {
				String cardapplicant = je.getAsJsonObject()
						.get("cardapplicant").getAsString();
				if (StrUtil.isEmpty(id) || StrUtil.isEmpty(cardapplicant)) {
					return Result.error("您配置的代理信息中存在单证领用人为空的,单证领用人不能为空");
				}
			}
			if (je.getAsJsonObject().get("branch") != null) {
				String branch = je.getAsJsonObject().get("branch")
						.getAsString();
				/** 广东销售信息 */
				if (StrUtil.isNotEmpty(branch) && branch.startsWith("44")) {
					list.add(id);
				}
			}
		}

		Result result = creditPlanService.updateAgentInfoRela(agent_type, list,
				user.getUserid(), plan_code, agentInfoListStr);

		return result;
	}

	/**
	 * 分页条件查询信保产品
	 * 
	 * @param page
	 * @param startDateBegin
	 * @param startDateEnd
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryCreditProdPageByCriteria")
	@ResponseBody
	public Page<CreditProduct> queryCreditProdPageByCriteria(
			Page<CreditProduct> page, CreditProduct creditProd,
			String startDateBegin, String startDateEnd) throws Exception {

		creditProd.setVstartDate(startDateBegin);
		creditProd.setVendDate(startDateEnd);
		creditProd.setStatus("1");
		page.setType(creditProd);

		page = creditPlanService.queryCreditProdPageByCriteria(page);
		return page;
	}

	/**
	 * 分页条件查询出单机构
	 * 
	 * @param page
	 * @param dept
	 * @param partnerNo
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryDeptPageByCriteria")
	@ResponseBody
	public Page<CoreDept> queryDeptPageByCriteria(HttpSession session,
			Page<CoreDept> page, CoreDept dept, String partnerNo)
			throws Exception {
		page.setType(dept);
		page.setObj(partnerNo);
		page.setObj(session.getAttribute(Constants.SESSION_USER));
		page = creditPlanService.queryDeptPageByCriteria(page);

		return page;
	}

	/**
	 * 加载个人代理、总对总代理信息、联合出单代理信息
	 * 
	 * @param page
	 * @param plan_code
	 * @param agentType
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryAgentInfoPageByCriteria")
	@ResponseBody
	public Page<Map<String, Object>> queryAgentInfoPageByCriteria(
			HttpSession session, Page<Map<String, Object>> page,
			String plan_code, String partner_code, String agent_type,
			String confStatus, String userCode, String userName, String branch,
			String branchName, String key1, String key2, String key3,
			String key4, String key5, String unionType) throws Exception {
		if (StrUtil.isEmpty(plan_code)) {
			page.setResult("plan_code不能为空");
			return page;
		}
		if (StrUtil.isEmpty(partner_code) && !"5".equals(agent_type)) {
			page.setResult("partnerNo不能为空");
			return page;
		}
		if (!("3".equals(agent_type) || "4".equals(agent_type)
				|| "5".equals(agent_type) || "7".equals(agent_type))) {
			page.setResult("agentType取值有误");
			return page;
		}
		// 登陆用户
		GatewayUser gatewayuser = (GatewayUser) session
				.getAttribute(Constants.SESSION_USER);
		Map<String, Object> paramMap = SqlUtil.buildPageMap(page);
		paramMap.put("planNo", plan_code);
		paramMap.put("partnerNo", partner_code);
		paramMap.put("agentType", agent_type);
		paramMap.put("confStatus", confStatus);
		paramMap.put("userCode", userCode);
		paramMap.put("userName", userName);
		paramMap.put("branch", branch);
		paramMap.put("branchName", branchName);
		paramMap.put("key1", key1);
		paramMap.put("key2", key2);
		paramMap.put("key3", key3);
		paramMap.put("key4", key4);
		paramMap.put("key5", key5);
		paramMap.put("unionType", unionType);
		paramMap.put("dept_code", gatewayuser.getDepartmentStr()
				.substring(1, 3));// 登陆用户出单机构（两位）
		page.setMap(paramMap);

		page = creditPlanService.queryAgentInfoPageByCriteria(page, agent_type);

		return page;
	}

	/**
	 * 总对总区域列表
	 * 
	 * @param page
	 * @param plan_code
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryAgentInfoZon4PageByCriteria")
	@ResponseBody
	public Page<Map<String, Object>> queryAgentInfoZon4PageByCriteria(
			Page<Map<String, Object>> page, String plan_code, String partnerNo,
			String isFlag, String branchName) throws Exception {
		if (StrUtil.isEmpty(plan_code)) {
			page.setResult("plan_code不能为空");
			return page;
		}

		Map<String, Object> paramMap = SqlUtil.buildPageMap(page);
		paramMap.put("planNo", plan_code);
		paramMap.put("partnerNo", partnerNo);
		if (StrUtil.isNotEmpty(branchName)) {
			paramMap.put("deptAbr", "%" + branchName + "%");
		} else {
			paramMap.put("deptAbr", null);
		}
		if (StrUtil.isEmpty(isFlag)) {
			paramMap.put("isFlag", null);
		} else {
			paramMap.put("isFlag", isFlag);

		}
		page.setMap(paramMap);

		page = creditPlanService.queryAgentInfoZon4PageByCriteria(page);

		return page;
	}

	/** 参数处理 */
	private String[] strToList(String branchs) {
		if (StrUtil.isNotEmpty(branchs)) {
			return branchs.split(",");
		}
		return null;
	}

	/**
	 * 新增方案
	 * 
	 * @param creditPlan
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/addOrUpdateCreditPlan")
	@ResponseBody
	public Result addOrUpdateCreditPlan(String planType, String saleArry,
			CreditPlan creditPlan, String oldplan_code, String oldPartnerNo,
			String oldAgentType) throws Exception {
		String planName = creditPlan.getPlan_name();
		if (StrUtil.isEmpty(planName))
			return Result.error("方案名称不能为空");

		String prodCode = creditPlan.getProd_code();
		if (StrUtil.isEmpty(prodCode))
			return Result.error("产品编号不能为空");

		String partnerNo = creditPlan.getPartner_code();
		if (StrUtil.isEmpty(partnerNo))
			return Result.error("合作伙伴代码不能为空");
		// 1、合作伙伴代理3、个人代理4、总对总代理
		CreditProduct creditProd = creditProductService
				.findProdInfoById(creditPlan.getProd_code());
		String agentType = creditPlan.getAgent_type();
		String dptCde = creditPlan.getDept_code();
		if ("1".equals(agentType)) {
			if (StrUtil.isEmpty(dptCde))
				return Result.error("出单机构不能为空");

			String channleCode = creditPlan.getChannel_code();
			if (StrUtil.isEmpty(channleCode))
				return Result.error("归属渠道不能为空");

			String channleType = creditPlan.getChannel_type();
			if (StrUtil.isEmpty(channleType))
				return Result.error("渠道类型不能为空");

			String newBsnsType = creditPlan.getNew_bsns_type();
			if (StrUtil.isEmpty(newBsnsType))
				return Result.error("业务来源不能为空");
		}
		// 1、合作伙伴代理3、个人代理4、总对总代理
		String empNo = creditPlan.getEmp_no();
		String teamCode = creditPlan.getTeam_code();
		String teamName = creditPlan.getTeam_name();
		String serviceCode = creditPlan.getService_code();
		if ("1".equals(agentType)) {
			if (StrUtil.isEmpty(empNo))
				return Result.error("业务员代码不能为空");
			if (StrUtil.isEmpty(teamCode))
				return Result.error("经办人所属团队不能为空");
			if (StrUtil.isEmpty(teamName))
				return Result.error("经办人归属机构名称");
			if (StrUtil.isEmpty(serviceCode))
				return Result.error("服务代码不能为空");
		}
		String isEpolicy = creditPlan.getIs_epolicy();
		if (StrUtil.isEmpty(isEpolicy))
			return Result.error("请选择是否电子保单");
		String plan_code = creditPlan.getPlan_code();
		Result result = null;
		if (StrUtil.isEmpty(plan_code)) {
			if (StrUtil.isEmpty(oldplan_code)) {// 新增
				result = creditPlanService
						.addCreditPlan(creditPlan, creditProd);
			} else {// 复制新增
				result = creditPlanService.copyAddCreditPlan(oldplan_code,
						oldPartnerNo, oldAgentType, creditPlan, creditProd);
			}
		} else {
			result = creditPlanService.updateCreditPlan(
					creditPlan, creditProd);
		}
		return result;
	}

	/**
	 * 编辑方案时，加载方案信息数据
	 * 
	 * @param plan_code
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/loadCreditPlan")
	@ResponseBody
	public Map<String, Object> loadCreditPlan(String plan_code)
			throws Exception {
		Map<String, Object> map = creditPlanService.loadCreditPlan(plan_code);
		/** 销售人员信息 */
		Map<String, String> salemap = new HashMap<String, String>();
		salemap.put("planCode", plan_code);
		List<TradPlanSale> sales = tradPlanSaleService.queryTrade(salemap);
		if (sales != null && sales.size() > 0) {
			/** 销售人员字典 */
			List<DictDto> dictDtos = DictCache.getDict("role_stype");
			map.put("sales", sales);
			for (TradPlanSale tradPlanSale : sales) {
				for (DictDto dictDto : dictDtos) {
					if (dictDto.getCode().equals(tradPlanSale.getPersonType())) {
						tradPlanSale.setSaleTypeName(dictDto.getCodeName());
					}
				}
			}
		}
		return map;
	}

	/**
	 * 跳转至编辑页面
	 * 
	 * @param model
	 * @param plan_code
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/toEditCreditPlan")
	public String toEditCreditPlan(ModelMap model, String plan_code)
			throws Exception {
		creditPlanService.toEditCreditPlan(model, plan_code);
		/** 编辑不显示上线按钮 */
		model.put("ptnEnv", "display:none");
		return "credit/plan/addOrEdit";
	}

	/**
	 * 添加/编辑成功后返回方案列表页面
	 * 
	 * @param flag
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/successBack")
	public String successBack(HttpServletRequest request, String flag)
			throws Exception {
		request.setAttribute("flag", flag);
		return "credit/plan/list";
	}

	/**
	 * 跳转至复制新增页面
	 * 
	 * @param model
	 * @param plan_code
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/toCopyAddcreditPlan")
	public String toCopyAddcreditPlan(ModelMap model, String plan_code)
			throws Exception {
		creditPlanService.toCopyAddCreditPlan(model, plan_code);
		return "credit/plan/addOrEdit";
	}

	/**
	 * 删除方案
	 * 
	 * @param creditPlan
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/delCreditPlan")
	@ResponseBody
	public Result delcreditPlan(CreditPlan creditPlan) throws Exception {

		Result result = creditPlanService.delCreditPlan(creditPlan);

		return result;
	}

	/**
	 * 加载方案关联个人代理、总对总代理信息、联合出单代理信息
	 * 
	 * @param page
	 * @param plan_code
	 * @param agentType
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryAgentInfoRelaPageByCriteria")
	@ResponseBody
	public Page<Map<String, Object>> queryAgentInfoRelaPageByCriteria(
			Page<Map<String, Object>> page, String plan_code, String agentType,HttpSession session)
			throws Exception {
		if (StrUtil.isEmpty(plan_code)) {
			page.setResult("plan_code不能为空");
			return page;
		}
		GatewayUser gatewayuser=(GatewayUser) session.getAttribute(Constants.SESSION_USER);
		if (!("3".equals(agentType) || "4".equals(agentType)
				|| "5".equals(agentType) || "6".equals(agentType) || "7"
					.equals(agentType))) {
			page.setResult("agentType取值有误");
			return page;
		}
		CreditPlan creditPlan = creditPlanService.queryById(plan_code);
		Map<String, Object> paramMap = SqlUtil.buildPageMap(page);
		paramMap.put("planNo", plan_code);
		paramMap.put("parentChannelCode", creditPlan.getPartner_code());
		if("4".equals(agentType)){
			paramMap.put("deptCodeStr", gatewayuser.getDepartmentStr());
		}
		page.setMap(paramMap);
		page = creditPlanService.queryAgentInfoRelaPageByCriteria(page,
				agentType);

		return page;
	}

	/***
	 * 方案配置清除
	 */
	@RequestMapping(value = "/clearAgentInfoZon4Div")
	@ResponseBody
	public Result clearAgentInfoZon4Div(String zonListStr, String branchs,
			String partner_code, String plan_code) throws Exception {
		Result result = null;
		try {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("planNo", plan_code);
			map.put("branchs", strToList(branchs));
			map.put("partnerNo", partner_code);
			/** 删除合作伙伴，机构下已关联的代理信息 */
			creditPlanService.delZonTradInfo(map);
			result = result.success("清除成功");
		} catch (Exception e) {
			logger.info(e);
			result = result.error("清除失败");
		}
		return result;
	}

	/**
	 * 跳转至复制新增页面
	 * 
	 * @param model
	 * @param planNo
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/toCopyAddCreditPlan")
	public String toCopyAddNlifePlan(ModelMap model, String plan_code)
			throws Exception {
		creditPlanService.toCopyAddCreditPlan(model, plan_code);
		return "credit/plan/addOrEdit";
	}
	
	@RequestMapping(value = "/dowloadPlan")
	public void dowloadPlan(String plan_code,HttpSession session,HttpServletResponse response,HttpServletRequest request) throws Exception {
		ServletOutputStream outPutStream=null;

		/**浏览器处理*/
	    final String userAgent = request.getHeader("USER-AGENT");
	    logger.info("使用的浏览器"+userAgent);
		 try{
			 String  fileName="信保方案sql.txt";
			 if(userAgent.indexOf( "MSIE")!=-1){
				 /**ie浏览器*/
				 fileName=java.net.URLEncoder.encode(fileName,"UTF-8"); 
			 }else if(userAgent.indexOf( "Mozilla")!=-1){
				 /**火狐浏览器*/
				 fileName = new String(fileName.getBytes(), "ISO8859-1");
			 }else{
				 /**其他浏览器*/
				 fileName=java.net.URLEncoder.encode(fileName,"UTF-8"); 
			 }
			 String[] planNos=forPlans(plan_code);
			 Map<String, Object> map=queryCredit(planNos);
			 /**查询产品信息*/
			 response.setContentType("text/plain"); 
			 response.setHeader("Content-disposition","attachment; filename="+fileName);  
	         outPutStream=response.getOutputStream(); 
	         String ss=FreeMarkerUtil.process("creditPlan.ftl", map);
	         outPutStream.write(ss.getBytes());  
	         outPutStream.flush();
		    }catch(IOException e){
		    	logger.info("创建文件出错",e);
		  }finally{
			  if(outPutStream!=null){
				  outPutStream.close();
			  }
		  }
	}
	/**产品导出数据处理
	 * @throws Exception **/
	private Map<String, Object> queryCredit(String[] plans) throws Exception{
		 Map<String, Object> map=new HashMap<String, Object>();
		 map.put("plans", plans);
		 /**导出方案*/
		 List<CreditPlan> creditPlans= creditPlanService.impCreditPlan(map);
		 /**导出方案组*/
		 List<TradInsuPlanGroup> groups= insuPlanGroupService.impNlifeGroup(map);
		 /**代理信息*/
		 List<TradAgentInfo> infos=nlifePlanConfigService.searchTradAgentInfosByplanCode(map);
		 /**查询网点信息**/
		 List<GatewaySubChannel> subs=subChannelService.searchGatewaySubChannelsListByplanCode(map);
		 /**导出方案代理关联信息*/
		 List<TradAgentInfoRela> agents=  nlifePlanConfigService.searchTradAgentInfoRelasByplanCode(map);
		 map.put("plans",creditPlans );
		 map.put("groups", groups);
		 map.put("agents", agents);
		 map.put("infos", infos);
		 map.put("subs", subs);
		return map;
	}
}
